<?php
/** Zend_Controller_Action */ 
require_once APPLICATION_PATH . '/../library/Soooner/Controller/Action.php';
class CompoundsolventController extends Soooner_Controller_Action
{
	private $_id;
	private $_modelCompoundsolvent;
	private $_modelDictionaryitems;
    public function init()
    {
        /* Initialize action controller here */
    	$this->initDzTemplate();
    	$this->_modelCompoundsolvent = new Model_Tables_Compoundsolvent();
    	$this->_modelDictionaryitems = new Model_Tables_Dictionaryitems();
    }
    /**
    * 获取溶剂列表
    * @return unknown_type
    */
    public function indexAction()
    {
    	/*$options = $GLOBALS['application']->getOptions();
    	$numPerPage = $options["pagecount"];//每页显示的条数
        $ItemCount =  $this->_modelCompoundsolvent->getCount();
        $PageCount = ceil($ItemCount/$numPerPage);
        $PageCount = $PageCount ? $PageCount : 1;*/
        $compoundid = $this->_getParam('compoundid');
        include $this->_dzTemplate->getFile( 'compoundsolvent.manage.html' );
    }
    /**
    * 获取溶剂列表
    * @return unknown_type
    */
    public function indexajaxAction()
    {
    	$solventlist = $this->_modelDictionaryitems->getDictionary(5);
    	$compoundid = $this->_getParam('compoundid');
        $options = $GLOBALS['application']->getOptions();
    	$numPerPage = $options["pagecount"];//每页显示的条数
        $page = intval($this->_getParam('page'));//默认页码
        $page = empty($page)?'1':$page;
   		$s = $this->_getParam('s'); 
        $ItemCount =  $this->_modelCompoundsolvent->getCount($s);
        $PageCount = ceil($ItemCount/$numPerPage);
        if($page>$PageCount)$page=$PageCount;
        $infos0 = $this->_modelCompoundsolvent->getList( $page, $numPerPage, $s,$compoundid );
        $infos = array();
        foreach($infos0 as $item){
        	$item[dict5]=$solventlist[$item[dict5]];
        	$infos[] = $item;
        }
        include $this->_dzTemplate->getFile( 'ajax/compoundsolvent.manage.ajax.html' );
    }
    /**
    * 添加溶剂
    * @return unknown_type
    */
    public function addAction()
    {
    	$solventlist = $this->_modelDictionaryitems->getDictionary(5);
    	$compoundid = $this->_getParam('compoundid');
    	$request = $this->getRequest();        
        if ($request->isPost())
        {
            $params =$request->getPost();
            $this->_modelCompoundsolvent->add($params);     
            echo "<script>opener.showsolvent();window.close();</script>";
            exit;
            //$this->_redirect("/compoundsolvent/index/compoundid/{$compoundid}");
        } 
        include $this->_dzTemplate->getFile( 'compoundsolvent.add.html' );
    }
    /**
    * 修改溶剂
    * @return unknown_type
    */
    public function modifyAction()
    {
    	$solventlist = $this->_modelDictionaryitems->getDictionary(5);
    	$compoundid = $this->_getParam('compoundid');
    	$id = $this->_getParam('id');
    	$info = $this->_modelCompoundsolvent->getInfo($id); 
        $request = $this->getRequest();        
        if ($request->isPost())
        {
        	$request =$request->getPost();        	
            if (true)//服务端检查输入参数
            {
                $this->_modelCompoundsolvent->modify($request,$id);
                echo "<script>opener.showsolvent();window.close();</script>";
                exit;
                //$this->_redirect("/compoundsolvent/index/compoundid/".$info["compoundid"]);
            }
        } 
        include $this->_dzTemplate->getFile( 'compoundsolvent.edit.html' );
    }
    /**
    * 无刷新修改溶剂
    * @return unknown_type
    */    
    public function modifyajaxAction()
    {
        $request = $this->getRequest();
        $params = $request->getPost();
        $arr = split("\|", $params['id']);
        $field = $arr[0];
        $id = $arr[1];
        $value = stripslashes($params['value']);
        $this->_modelCompoundsolvent->modifyAjax($id,$field,$value);
        echo $value;
        exit;
    }
    public function modifyajaxreversAction()
    {
    	$field = $this->_getParam('field');
    	$pri = $this->_getParam('pri');
        $this->_modelCompoundsolvent->modifyAjaxRevers($field,$pri);
        exit;
    }
    /**
    * 删除溶剂
    */
    public function deleteAction()
    {
        $id = $this->_getParam('id');   
        $this->_modelCompoundsolvent->del($id); 
        exit;
    }
}